<?php
global $directory;
$active = JFactory::getApplication()->getMenu()->getActive();
$input = &JFactory::getApplication()->input;
$catId = $input->getInt("cat_id");
$menuSelected = $catId ? "" : 'selected';
?>
<div class="inner_title">
    <ul>
        <li><div class="sub_item"><a href="<?php echo JRoute::_("index.php?option=com_works&view=works"); ?>" class="<?php echo $menuSelected; ?>"><?php echo JTEXT::_('ALL'); ?></a><div class="sub_bg"></div></div></li>
        <?php
        foreach ($this->categories as $cat) {
            $link = JRoute::_("index.php?option=com_works&view=works&cat_id={$cat->id}");
            ?>
            <li><div class="sub_item"><a class="<?php echo ($catId == $cat->id ? "selected" : ""); ?>" href="<?php echo $link; ?>"><?php echo $cat->title; ?></a><div class="sub_bg"></div></div></li>
        <?php } ?>
    </ul>
    <br class="clear" />
</div>
<div id="content">
    <?php
    if (is_array($this->items) && count($this->items)) {
        foreach ($this->items as $item) {
            $registry = new JRegistry;
            $registry->loadString($item->file);
            $item->file = $registry->toArray();
            $thumb = "";
            if (isset($item->file['image']) && $item->file['image']) {
                $thumb = JUri::base() . DS . "images/{$directory}/{$item->file['image']}";
            } else {
                $thumb = "images/fixed/0170c.jpg";
            }
            $link = JRoute::_("index.php?option=com_works&view=work&cat_id={$item->category_id}&id={$item->id}");
            ?>
            <div class="item">
                <div class="info_box">
                    <div class="caption">
                        <a class="title" href="<?php echo $link; ?>"><?php echo $item->title; ?></a>
                        <p> <?php echo trimstr($item->short_desc, 100); ?></p>
                        <div class="link_btn"><a href="<?php echo $link; ?>"><?php echo JText::_('View detail'); ?></a></div>
                    </div>
                    <div class="img"><a href="<?php echo $link; ?>"><img src="timthumb.php?src=<?php echo $thumb; ?>&w=317&h=211"  /></a></div>
                </div>
            </div>
            <?php
        }
    }
    ?>
    <br class="clear" />

</div>